//
//  Labs_TableVC.swift
//  APSwift
//
//  Created by jianbo.pei on 2022/3/10.
//

import UIKit

class Labs_TableVC: UIViewController {
    
    lazy var tableView: UITableView = {
        let tableV = UITableView(frame: view.bounds, style: .plain)
        tableV.delegate = self
        tableV.dataSource = self
        tableV.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
        return tableV
    }()
    
    var cellTitles: [String] = []
    var cellVCNames: [String] = []
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        view.backgroundColor = .white
        
        configDatas()
        view.addSubview(tableView)
    }
    
    func configDatas() {
        cellTitles = [
            "虾兵蟹将系列",
            "String试验",
            "全面学习LLDB",
            "内存管理",
            "标准单例",
            "UIButton点击和松开",
            "UIButton高亮图片",
            "系统侧滑、push完成、pop完成",
            "runtime",
            "charts"
        ]
        
        cellVCNames = [
            "Labs_XBXJ_TableVC",
            "Labs_String_DemoVC",
            "Labs_LLDB_TableVC",
            "Labs_MemoryManagement_TableVC",
            "Labs_Singleton_DemoVC",
            "Labs_UIButtonTouch_DemoVC",
            "Labs_UIButtonHighlightedImage_DemoVC",
            "Labs_DidMovetoParent_A_DemoVC",
            "Labs_Runtime_TableVC",
            "Labs_Charts_TableVC"
        ]
    }
    
}

extension Labs_TableVC: UITableViewDataSource, UITableViewDelegate {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return cellTitles.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
        cell.textLabel?.text = cellTitles[indexPath.row]
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 60
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        pushToNext(vcTitles: cellTitles, vcNames: cellVCNames, at: indexPath)
    }
}
